﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace SomeKit.Http
{
    public static partial class HttpHelper
    {
        /// <summary>
        /// Executes the verb <paramref name="verb"/> on the resource <paramref name="uri"/>.
        /// </summary>
        /// <param name="uri">The address of the resource to be accessed.</param>
        /// <param name="verb">The verb/method to be invoked on resource <paramref name="uri"/>.</param>
        /// <param name="contentType">The type of the content in the request. Usually application/xml or application/json.</param>
        /// <param name="acceptType">The type accepted by caller. Usually application/xml or appication/json.</param>
        /// <param name="resultHandler">The delegate to be invoked in case of success.</param>
        /// <param name="errorHandler">The delegate to be invoked in case of failure.</param>
        /// <param name="body">The body of the request.</param>
        /// <param name="headerHandler">The delegate provided for custom header customization.</param>
        public static void SendRequest(this Uri uri, string verb, string contentType, string acceptType, 
            Action<string> resultHandler, Action<Exception> errorHandler, 
            string body = null, Action<HttpWebRequest> headerHandler = null)
        {
            var request = uri.GetRequest(verb, headerHandler);
            request.SetContentType(contentType);
            request.SetAcceptType(acceptType);
            request.SendRequest(body, resultHandler, errorHandler);
        }
    }
}
